package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.LinkAccount;
import com.ruoyi.system.service.ILinkAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教师关联账号信息Controller
 * 
 * @author bearzz
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/teacher/linkAccount")
public class LinkAccountController extends BaseController
{
    @Autowired
    private ILinkAccountService linkAccountService;

    /**
     * 查询教师关联账号信息列表
     */
    @RequiresPermissions("teacher:teacher:list")
    @GetMapping("/list")
    public TableDataInfo list(LinkAccount linkAccount)
    {
        startPage();
        List<LinkAccount> list = linkAccountService.selectLinkAccountList(linkAccount);
        return getDataTable(list);
    }

    /**
     * 导出教师关联账号信息列表
     */
    @RequiresPermissions("teacher:teacher:export")
    @Log(title = "教师关联账号信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkAccount linkAccount)
    {
        List<LinkAccount> list = linkAccountService.selectLinkAccountList(linkAccount);
        ExcelUtil<LinkAccount> util = new ExcelUtil<LinkAccount>(LinkAccount.class);
        util.exportExcel(response, list, "教师关联账号信息数据");
    }

    /**
     * 获取教师关联账号信息详细信息
     */
    @RequiresPermissions("teacher:teacher:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(linkAccountService.selectLinkAccountById(id));
    }

    /**
     * 新增教师关联账号信息
     */
    @RequiresPermissions("teacher:teacher:add")
    @Log(title = "教师关联账号信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkAccount linkAccount)
    {
        return toAjax(linkAccountService.insertLinkAccount(linkAccount));
    }

    /**
     * 修改教师关联账号信息
     */
    @RequiresPermissions("teacher:teacher:edit")
    @Log(title = "教师关联账号信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkAccount linkAccount)
    {
        return toAjax(linkAccountService.updateLinkAccount(linkAccount));
    }

    /**
     * 删除教师关联账号信息
     */
    @RequiresPermissions("teacher:teacher:remove")
    @Log(title = "教师关联账号信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(linkAccountService.deleteLinkAccountByIds(ids));
    }
}
